package cn.kgc.crowdfundingadminspringboot.service.impl;

import cn.kgc.crowdfundingadminspringboot.mapper.CertMapper;
import cn.kgc.crowdfundingadminspringboot.pojo.Cert;
import cn.kgc.crowdfundingadminspringboot.pojo.CertExample;
import cn.kgc.crowdfundingadminspringboot.pojo.Role;
import cn.kgc.crowdfundingadminspringboot.pojo.RoleExample;
import cn.kgc.crowdfundingadminspringboot.service.CertService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CertServiceImpl implements CertService{
    @Resource
    private CertMapper certMapper;
    @Override
    public PageInfo<Cert> queryForKeywordSearch(Integer pageNum, Integer pageSize, String keyword) {
        PageHelper.startPage(pageNum,pageSize);
        PageHelper.orderBy("id desc");
        PageInfo<Cert> pageInfo=null;
        if (keyword!=null&&keyword.length()>0){
            CertExample example=new CertExample();
            CertExample.Criteria criteria = example.createCriteria();
            criteria.andNameLike("%"+keyword+"%");
            List<Cert> list=certMapper.selectByExample(example);
            pageInfo=new PageInfo<>(list);
        }else{
            List<Cert> list=certMapper.selectByExample(null);
            pageInfo=new PageInfo<>(list);
        }
        return pageInfo;
    }

    @Override
    public List<Cert> getCertListByIdList(List<Integer> certIdList) {
        // 创建实体类Role对应的Example对象
        CertExample certExample = new CertExample();

        // 在Example对象中封装查询条件
        certExample.createCriteria().andIdIn(certIdList);
        // 执行查询
        return certMapper.selectByExample(certExample);
    }
    @Override
    public void batchRemove(List<Integer> certIdList) {

        CertExample certExample = new CertExample();

        certExample.createCriteria().andIdIn(certIdList);

        certMapper.deleteByExample(certExample);
    }
    @Override
    public void saveRole(String certName) {
        certMapper.insert(new Cert(null, certName));
    }
}
